package com.music.service.impl;

import com.music.common.BaseResult;
import com.music.dao.CmFriendMapper;
import com.music.entity.FriendUser;
import com.music.service.CmFriendService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CmFriendServiceImpl implements CmFriendService {
    @Autowired
    private CmFriendMapper cmFriendMapper;
    @Override
    public BaseResult insertFriend(Integer uId, Integer uaId) {
//        System.out.println(uId);
//        System.out.println(uaId);
        int i = cmFriendMapper.insertFriend(uId, uaId);
        BaseResult baseResult = new BaseResult();
        if (i!=0){
            baseResult.setMessage("关注成功");
            baseResult.setCode(200);
            return baseResult;
        }else{
            baseResult.setMessage("关注失败");
            baseResult.setCode(201);
            return baseResult;
        }
    }

    @Override
    public BaseResult findNameById(Integer uId) {
        List<FriendUser> nameById = cmFriendMapper.findNameById();
        BaseResult baseResult = new BaseResult();
        if (nameById!=null){
            baseResult.setMessage("查询成功");
            baseResult.setCode(200);
            baseResult.setData(nameById);
            return baseResult;
        }else{
            baseResult.setCode(201);
            baseResult.setMessage("查询失败");
            return baseResult;
        }
    }
    @Override
    public BaseResult findFriendByUid(Integer uId) {
        List<FriendUser> friendByUid = cmFriendMapper.findFriendByUid(uId);
        BaseResult baseResult = new BaseResult();
        if (friendByUid!=null){
            baseResult.setData(friendByUid);
            baseResult.setMessage("关注成功");
            baseResult.setCode(200);
            return baseResult;
        }else{
            baseResult.setCode(201);
            baseResult.setMessage("关注失败");
            return baseResult;
        }
    }

    @Override
    public BaseResult deleteFriendByUaid(Integer uaId,Integer uId) {
        int i = cmFriendMapper.deleteFriendByUaid(uaId,uId);
        BaseResult baseResult = new BaseResult();
        if (i!=0){
            baseResult.setMessage("取关成功");
            baseResult.setCode(200);
            return baseResult;
        }else{
            baseResult.setMessage("取关失败");
            baseResult.setCode(201);
            return baseResult;
        }
    }
}
